import { http } from "@/utils/http/axios";
import type { AxiosResponse } from "axios";
/**
 * 获取菜单树
 * @returns
 */

export function getList(params = {}) {
	return http.request<API.Response.BasicResponse>(
		{
			url: "/system/menu/list",
			method: "get",
			params
		},
		{
			isTransformResponse: false
		}
	);
}

//获取应用列表
export function getListByAppId(params = {}) {
	return http.request<API.Response.BasicResponse>(
		{
			url: `/system/menu/getMenuByAppId`,
			method: "get",
			params
		},
		{
			isTransformResponse: true
		}
	);
}

/**
 * 获取菜单选择树
 * @returns
 */
export function tree(params = {}) {
	return http.request<API.Response.BasicResponse>(
		{
			url: "system/menu/tree",
			method: "get",
			params
		},
		{
			isTransformResponse: true
		}
	);
}

/**
 * 添加菜单
 * @returns
 */
export function save(params = {}) {
	return http.request<API.Response.BasicResponse>({
		url: "system/menu",
		method: "post",
		data: params
	});
}

/**
 * 刪除
 * @returns
 */
export function remove(id: number) {
	return http.request<API.Response.BasicResponse>(
		{
			url: `system/menu/${id}`,
			method: "delete"
		},
		{
			isTransformResponse: true
		}
	);
}

/**
 * 更新数据
 * @returns
 */
export function update(data = {}) {
	return http.request<API.Response.BasicResponse>({
		url: "system/menu",
		method: "put",
		data
	});
}
/**
 * 根据ID查询
 * @param id
 * @returns
 */
export function getMenu(id: number | undefined) {
	return http.request(
		{
			url: "system/menu/" + id,
			method: "get"
		},
		{
			isTransformResponse: true
		}
	);
}
/**
 * 更改菜单状态
 * @returns
 */
export function changeStatus(data = {}) {
	return http.request<API.Response.BasicResponse>(
		{
			url: "system/menu/changeStatus",
			method: "put",
			data
		},
		{
			isTransformResponse: true
		}
	);
}
